package com.shopping.mapper;

import com.shopping.pojo.Browse;
import com.shopping.pojo.Cart;
import com.shopping.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    //用户登录
    @Select("select * from user where username=#{username} and password = #{password}")
    User getByUsernameByPassword(User user);
    //管理员登录
    @Select("select * from admin where username=#{username} and password = #{password}")
    User getByAdminnameByPassword(User user);
    //用户注册，保存用户
    @Insert("insert into user(username, password,email) value (#{username},#{password},#{email})")
    void insert(User user);
    //按照用户名查找用户
    @Select("select * from user where username=#{username}")
    User searchByUsername(String username);
    @Select("select * from admin where username=#{username}")
    User searchByAdminname(String username);

    //根据id获取顾客名
    @Select("select username from user where id=#{customerId}")
    String getUserName(int customerId);
    //注销用户
    @Delete("DELETE FROM user WHERE id = #{customerId}")
    void deleteUser(Integer customerId);
    //获取用户列表
    @Select("select * from user")
    List<User> getUSerList();

    //获取用户浏览日志
    @Select("select * from browse where user_id =#{id} ORDER BY browse_time DESC")
    List<Browse> getBrowseLog(Integer id);
    //获取用户购买日志
    @Select("select * from order_item where status = 1 AND user_id=#{id} ORDER BY purchase_time DESC")
    List<Cart> getOrderLog(Integer id);
}
